using System;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNetNuke;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Localization;
using DotNetNuke.Services.Exceptions;
using gdlmo.DNN.Modules.Article.Business;
using gdlmo.Common;
namespace gdlmo.DNN.Modules.Article
{
	public abstract class ArticleSearch : PortalModuleBase, IActionable, IPortable, ISearchable 
	{
		protected System.Web.UI.WebControls.DropDownList cboCategory;
		protected System.Web.UI.WebControls.Button btnSearch;
		protected System.Web.UI.WebControls.LinkButton lnkSearch;
		protected System.Web.UI.WebControls.TextBox txtKey;
				
		#region Private Member
		
		#endregion

		#region Private Function
		private void BindCategory()
		{			
			cboCategory.DataTextField = "Name";
			cboCategory.DataValueField = "CategoryId";
			cboCategory.DataSource = new CategoryController().GetByModules(ModuleId);
			cboCategory.DataBind();
			cboCategory.Items.Insert(0,new ListItem(Localization.GetString("AllCategory",this.LocalResourceFile),"0")); 			
		}
		#endregion

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{			
			this.lnkSearch.Click += new System.EventHandler(this.lnkSearch_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		#region Event Handlers

		private void Page_Load(object sender, System.EventArgs e)
		{
			try 
			{
				if(!Page.IsPostBack)
				{
					BindCategory();
				}
			}
			catch (Exception exc) 
			{
				Exceptions.ProcessModuleLoadException(this, exc);
			}
		}
		#endregion

		#region Optional Interfaces
		public DotNetNuke.Entities.Modules.Actions.ModuleActionCollection ModuleActions 
		{
			get 
			{
				DotNetNuke.Entities.Modules.Actions.ModuleActionCollection Actions = new DotNetNuke.Entities.Modules.Actions.ModuleActionCollection();
				Actions.Add(GetNextActionID(), Localization.GetString(DotNetNuke.Entities.Modules.Actions.ModuleActionType.AddContent, LocalResourceFile), DotNetNuke.Entities.Modules.Actions.ModuleActionType.AddContent, "", "", EditUrl(), false, DotNetNuke.Security.SecurityAccessLevel.Edit, true, false);
				return Actions;
			}
		}

		public string ExportModule(int ModuleID)
		{
			// included as a stub only so that the core knows this module Implements Entities.Modules.IPortable
			return null;
		}

		public void ImportModule(int ModuleID, string Content, string Version, int UserID)
		{
			// included as a stub only so that the core knows this module Implements Entities.Modules.IPortable
		}

		public DotNetNuke.Services.Search.SearchItemInfoCollection GetSearchItems(ModuleInfo ModInfo)
		{
			// included as a stub only so that the core knows this module Implements Entities.Modules.ISearchable
			return null;
		}

		#endregion				

		private void lnkSearch_Click(object sender, System.EventArgs e)
		{
			string [] Params  = new string[2];
			
			Params[0] = "Title=" + txtKey.Text.Trim();			
			Params[1] = "Summary=";			
			Response.Write("<script language=javascript>window.open('" + EditUrl("CategoryId",cboCategory.SelectedValue.ToString(),"ListMore",Params) +"')</script>"); 
			//Response.Redirect( EditUrl("CategoryId",cboCategory.SelectedValue.ToString(),"ListMore",Params));
		}
	}
}
